home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F25229_ViewSourceDialog.java < prev    next >
Encoding:
Java Source  |  2000-11-10  |  7.1 KB  |  185 lines

  1. /*
  2.     Rob Mayfield. IMSI @1997
  3.     This creates a dialog which contains a text window and scrollbars.
  4.     The text window uses a small subset of HTML to display multiple color
  5.     in the text. This is done in the displayText class.
  6. */
  7.  
  8. import java.awt.*;
  9. import textDisplay;
  10.  
  11. public class ViewSourceDialog extends Dialog
  12. {
  13.     public ViewSourceDialog(Frame parent, boolean modal, String popUpString)
  14.     {
  15.  
  16.         super(parent, modal);
  17.           dHeight = 305; dWidth = 405;
  18.         setLayout(null);
  19.         addNotify();
  20.         resize(insets().left + insets().right + dWidth,insets().top + insets().bottom + dHeight);
  21.         setBackground(new Color(15790320));
  22.  
  23.         buttonPanel = new java.awt.Panel();
  24.         //buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
  25.         buttonPanel.setLayout(null);
  26.         buttonPanel.reshape(insets().left , insets().top + 0, size().width - insets().left - insets().right - 5, 31);
  27.         buttonPanel.setBackground(new Color(15790320));
  28.         add(buttonPanel);
  29.  
  30.         buttonExit = new java.awt.Button("Exit");
  31.         //buttonExit.reshape(271,5,36,21);
  32.         buttonExit.reshape((buttonPanel.size().width/2)-18, 5,36,21);
  33.         buttonPanel.add(buttonExit);
  34.  
  35.         textDisp = new textDisplay();
  36.         textDisp.reshape(insets().left + 10, insets().top + 31, size().width - 18 - 15, size().height - insets().top - 31 - 15 - insets().bottom);  // 576, 360
  37.         textDisp.setBackground(new Color(15790320));
  38.         // set the text for the popup help
  39.         textDisp.setText(popUpString);
  40.         add(textDisp);
  41.  
  42.         // NOTE: scroll bars should be moved to the textDisplay Class
  43.         // The scrollbars are instanciated with 0 initial position, thumb size of 10, min of 0 max of 99 
  44.         verticalScrollbar = new java.awt.Scrollbar(Scrollbar.VERTICAL, 0, 10, 0, 250);
  45.         verticalScrollbar.reshape(size().width - (insets().left*2) - 11, insets().top + 31, 15, size().height - insets().top - 31 - 16 -insets().bottom);  // 578 , 360
  46.         //verticalScrollbar.setBackground(new Color(15790320));
  47.         verticalScrollbar.setLineIncrement(1);
  48.         verticalScrollbar.setPageIncrement(25);
  49.         add(verticalScrollbar);
  50.  
  51.         // The scrollbars are instanciated with 0 initial position, thumb size of 6 (different length from verticle), min of 0 max of 99
  52.         horizontalScrollbar = new java.awt.Scrollbar(Scrollbar.HORIZONTAL, 0, 6, 0, 250);
  53.         horizontalScrollbar.reshape(insets().left, size().height - 16 - insets().bottom, size().width - 10 - (insets().left*2) - 5, 15);
  54.         horizontalScrollbar.setLineIncrement(1);
  55.         horizontalScrollbar.setPageIncrement(25);
  56.         add(horizontalScrollbar);
  57.  
  58.         setTitle("Source Viewer");
  59.         //textDisp = new textDisplay("This is a <br>longer test<br> string which make <FONT color="#FFFF00">for viewing tests<br>");
  60.         //buttonPanel.reshape(insets().left , insets().top + 0, size().width - insets().left - insets().right - 5, 31);
  61.         //textDisp.reshape(insets().left + 10, insets().top + 31, size().width - 18 - 15, size().height - insets().top - 31 - 15 - insets().bottom);  // 576, 360
  62.         //verticalScrollbar.reshape(size().width - (insets().left*2) - 11, insets().top + 31, 15, size().height - insets().top - 31 - 16 -insets().bottom);  // 578 , 360
  63.         //horizontalScrollbar.reshape(insets().left, size().height - 16 - insets().bottom, size().width - 10 - (insets().left*2) - 5, 15);
  64.         Dim = new Dimension (size().width, size().height);
  65.     }
  66.  
  67.     public ViewSourceDialog(Frame parent, String title, boolean modal)
  68.     {
  69.         this(parent, modal, (String)null);
  70.         setTitle(title);
  71.     }
  72.     
  73.     public void paint(java.awt.Graphics g)
  74.     {
  75.            if ((Dim.width != size().width) || (Dim.height != size().height))
  76.            {
  77.             buttonPanel.reshape(insets().left , insets().top + 0, size().width - insets().left - insets().right - 5, 31);
  78.             buttonExit.reshape((buttonPanel.size().width/2)-18, 5,36,21);
  79.             textDisp.reshape(insets().left + 10, insets().top + 31, size().width - 18 - 15, size().height - insets().top - 31 - 15 - insets().bottom);  // 576, 360
  80.             verticalScrollbar.reshape(size().width - (insets().left*2) - 11, insets().top + 31, 15, size().height - insets().top - 31 - 16 -insets().bottom);  // 578 , 360
  81.             horizontalScrollbar.reshape(insets().left, size().height - 16 - insets().bottom, size().width - 10 - (insets().left*2) - 5, 15);    
  82.         }
  83.     }
  84.  
  85.     public synchronized void show()
  86.     {
  87.         Rectangle bounds = getParent().bounds();
  88.         Rectangle abounds = bounds();
  89.         // center window over parent
  90.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  91.              bounds.y + (bounds.height - abounds.height)/2);
  92.  
  93.         super.show();
  94.     }
  95.  
  96.     public boolean handleEvent(Event event)
  97.     {
  98.         if(event.id == Event.WINDOW_DESTROY)
  99.         {
  100.             hide();
  101.             return true;
  102.         }
  103.         if (event.target == buttonExit && event.id == Event.ACTION_EVENT)
  104.         {
  105.             dispose();
  106.             return true;
  107.         }
  108.  
  109.         if (event.target == verticalScrollbar && event.id == Event.SCROLL_ABSOLUTE) 
  110.         {
  111. //System.out.println(event.toString());
  112.             textDisp.verticalScrollbarAction(Event.SCROLL_ABSOLUTE, event.arg);
  113.             return true;
  114.         }
  115.  
  116.         // Handle scrollbar events  NOTE: scrollbars should be move to textDispaly class
  117.         if (event.target == verticalScrollbar && event.id == Event.SCROLL_LINE_UP) 
  118.         {
  119.             textDisp.verticalScrollbarAction(Event.SCROLL_LINE_UP, event.arg);
  120.             return true;
  121.         }
  122.  
  123.         if (event.target == verticalScrollbar && event.id == Event.SCROLL_LINE_DOWN) 
  124.         {
  125.             textDisp.verticalScrollbarAction(Event.SCROLL_LINE_DOWN, event.arg);
  126.             return true;
  127.         }
  128.  
  129.         if (event.target == verticalScrollbar && event.id == Event.SCROLL_PAGE_UP) 
  130.         {
  131.             textDisp.verticalScrollbarAction(Event.SCROLL_PAGE_UP, event.arg);
  132.             return true;
  133.         }
  134.  
  135.         if (event.target == verticalScrollbar && event.id == Event.SCROLL_PAGE_DOWN) 
  136.         {
  137.             textDisp.verticalScrollbarAction(Event.SCROLL_PAGE_DOWN, event.arg);
  138.             return true;
  139.         }
  140.  
  141.  
  142.         if (event.target == horizontalScrollbar && event.id == Event.SCROLL_LINE_UP) 
  143.         {
  144.             textDisp.horizontalScrollbarAction(Event.SCROLL_LINE_UP, event.arg);
  145.             return true;
  146.         }
  147.  
  148.         if (event.target == horizontalScrollbar && event.id == Event.SCROLL_LINE_DOWN) 
  149.         {
  150.             textDisp.horizontalScrollbarAction(Event.SCROLL_LINE_DOWN, event.arg);
  151.             return true;
  152.         }
  153.  
  154.         if (event.target == horizontalScrollbar && event.id == Event.SCROLL_PAGE_UP) 
  155.         {
  156.             textDisp.horizontalScrollbarAction(Event.SCROLL_PAGE_UP, event.arg);
  157.             return true;
  158.         }
  159.  
  160.         if (event.target == horizontalScrollbar && event.id == Event.SCROLL_PAGE_DOWN) 
  161.         {
  162.             textDisp.horizontalScrollbarAction(Event.SCROLL_PAGE_DOWN, event.arg);
  163.             return true;
  164.         }
  165.  
  166.         if (event.target == horizontalScrollbar && event.id == Event.SCROLL_ABSOLUTE) 
  167.         {
  168. //System.out.println(event.toString());
  169.             textDisp.horizontalScrollbarAction(Event.SCROLL_ABSOLUTE, event.arg);
  170.             return true;
  171.         }
  172.  
  173.         return super.handleEvent(event);
  174.     }
  175.  
  176.     java.awt.Panel buttonPanel;
  177.     java.awt.Button buttonExit;
  178.     java.awt.Scrollbar verticalScrollbar;
  179.     java.awt.Scrollbar horizontalScrollbar;
  180.     textDisplay textDisp;    
  181.     Dimension Dim;
  182.     int dHeight, dWidth;
  183. }
  184.  
  185.